#ifndef ROVIO_H
#define ROVIO_H

/********** Library Includes **************************************************/

#include <curl/curl.h>

/********** Local Includes ****************************************************/

#include "robot_structures.h"

/********** Classes ***********************************************************/

/**
 * A class to provide an abstraction to communications with the Rovio.
 */
class Rovio {
public:
	static const int DEFAULT_SPEED = 5;
	
	explicit Rovio(std::string url, int defaultSpeed = DEFAULT_SPEED);
	~Rovio();
	
	/**
	 * Saves an image pulled from the Rovio's onboard camera.
	 */
	bool saveImage(const std::string &filename = "rovio_img.jpg");
	
	/**
	 * Drives in the given direction at the given speed.
	 * 
	 * @param dir The direction to drive, as specified in the DriveDirection enum
	 * @param speed The speed to drive, 1 - 10, as specified in the Rovio API
	 */
	CURLcode drive(DriveDirection dir, int speed);
	
	/**
	 * Drives in the given direction at the default speed.
	 *
	 * @param dir The direction to drive, as specified in the DriveDirection enum
	 */
	CURLcode drive(DriveDirection dir);
	
	/**
	 * Drives in the given direction for the given amount of time at the given
	 * speed.
	 *
	 * @param dir The direction to drive, as specified in the DriveDirection enum
	 * @param time The time to drive, in milliseconds
	 * @param speed The speed to drive, 1 - 10, as specified in the Rovio API
	 */
	void timeDrive(DriveDirection dir, int time, int speed);
	
	/**
	 * Drives in the given direction for the given amount of time at the given
	 * speed.
	 *
	 * @param dir The direction to drive, as specified in the DriveDirection enum
	 * @param time The time to drive, in milliseconds
	 * @param speed The speed to drive, 1 - 10, as specified in the Rovio API
	 */
	void timeDrive(DriveDirection dir, int time);
	
	/**
	 * Convenience method to drive the robot straight for a given amount of
	 * time at the default speed.
	 *
	 * @param time The amount of time to drive, in milliseconds, or -1 to
	 *		execute exactly one command
	 */
	void driveForward(int time = -1);
	
	/**
	 * Convenience method to turn the robot left for a given amount of time at
	 * the default speed.
	 *
	 * @param time The amount of time to turn, in milliseconds, or -1 to execute
	 *		exactly one command
	 */
	void turnLeft(int time = -1);
	
	/**
	 * Convenience method to turn the robot right for a given amount of time at
	 * the default speed.
	 *
	 * @param time The amount of time to turn, in milliseconds, or -1 to execute
	 *		exactly one command
	 */
	void turnRight(int time = -1);
	
	/**
	 * Changes the default speed.
	 */
	void setDefaultSpeed(int defaultSpeed);
	
	/**
	 * Returns the default speed.
	 */
	int defaultSpeed() const;

private:
	CURL *m_curl;
	std::string m_url;
	int m_defaultSpeed;
};

#endif